<?php
namespace app\store\controller;

use app\common\controller\Api;
use think\Db;

/****
 * Class    Printer
 * @name    打印机API文件
 * @author  晓月老板<1434926265@qq.com>
 * @date    2020/05/20 11:34 AM
 * @package app\api\controller
 */
class Printer extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    // 默认方法
    public function _initialize()
    {
        parent::_initialize();

        // 打印机接口
        $this->model = new \app\admin\model\Printer;

        // 获取店铺ID
        $this->store_id = $this->request->request("store_id",0,"intval");
    }


    /***
     * @name    商户打印机信息
     * @author  晓月老板<1434926265@qq.com>
     * @date    2020/05/22 14:51 PM
     * @return  string<json>
     */
    public function printer_info()
    {

        $where = array();

        $where['status'] = 'normal';

        $where['store_id'] = $this->store_id;

        $printer_info = Db::name('printer')->where($where)->find();

        $printer_info['param'] = \GuzzleHttp\json_decode($printer_info['param'],true);

        $this->success('请求成功', $printer_info);

    }


    /***
     * @name    编辑商户打印机信息
     * @author  晓月老板<1434926265@qq.com>
     * @date    2020/05/22 14:51 PM
     * @return  string<json>
     */
    public function edit_printer_info()
    {

        $params = $this->request->post("params",'','htmlspecialchars_decode');

        $id = $this->request->post("id",0,'intval');

        $result = Db::name('printer')->where(['status' => 'normal','store_id' => $this->store_id,'id' => $id])->update(['param'=>$params]);

        if($result !== false){
            $this->success('配置成功');
        }else{
            $this->error('配置失败');
        }

    }


}
